/*
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-04-18 17:27:16
 * @LastEditTime: 2021-04-24 23:18:39
 */

const path = require('path');
const HtmlWebpackPlugin= require('html-webpack-plugin');

const DonePlugin = require('./plugins/DonePlugin');
const AsyncPlugin = require('./plugins/AsyncPlugin');
const FileListPlugin = require('./plugins/FileListPlugin');

module.exports = {
    // development || production
    mode: 'development',
    entry: "./src/main.js",
    devtool: 'source-map',
    output: {
        filename: "bundle.js",
        path: path.resolve(__dirname, "dist"),
    },
    resolveLoader: {
        // 先在node_modules中找相关use loader, 没有则在loader 目录中找
        modules: ['node_modules', path.resolve(__dirname, 'loader')],
        // 转为loader用的别名
        // alias: {
        //     loader1: path.resolve(__dirname, 'loader/loader1.js'),
        // }
    },
    module: {
        // loader的顺序：从右到左, 从下到上
        // loader的分类顺序：  pre(前面)  normal(中间)  inline(行内)  post(最后)
        // loader执行时分： pitch  和  normal 
        rules: [
            // {
            //     test: /\.js$/,
            //     use: path.resolve(__dirname, 'loader', 'loader1.js')
            // },

            // {
            //     test: /\.js$/,
            //     use: ['loader1', 'loader2'],
            //     enforce: 'pre'
            // },
            // {
            //     test: /\.js/,
            //     use: 'loader3',
            //     enforce: 'post'
            // },

            {
                test: /\.js$/,
                use: [{
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env']
                    },
                }],
            },

            // {
            //     test: /\.less$/,
            //     use: [
            //         path.resolve(__dirname, 'loader', 'style-loader'),
            //         path.resolve(__dirname, 'loader', 'less-loader')
            //     ]
            // },

            {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader'],
            },



        ]


    },
    plugins: [
        // new DonePlugin(),
        // new AsyncPlugin(),

        new HtmlWebpackPlugin({
            template: './src/index.html'
        }),
        // new FileListPlugin({
        //     filename: 'list.md'
        // }),
    ]

}

